package com.xintoucloud.springbootguide.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.xintoucloud.springbootguide.config.ClazzJsonDeserializer;
import org.hibernate.annotations.Type;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.util.Date;

@Entity
@Table(name="t_stu")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Student {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer sid;
	private String sname;
	private String address;
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	@Type(type = "date")
	private Date birthday;
	private String pic;
	private String cardId;
	private String gender;
	
	@ManyToOne
	//@JsonIgnore
	@JsonDeserialize(using = ClazzJsonDeserializer.class)
	private Clazz clazz;

	public Clazz getClazz() {
		return clazz;
	}
	public void setClazz(Clazz clazz) {
		this.clazz = clazz;
	}
	public String getGender() {
		return gender;
	}
	public void setGender(String gender) {
		this.gender = gender;
	}
	public Integer getSid() {
		return sid;
	}
	public void setSid(Integer sid) {
		this.sid = sid;
	}
	public String getSname() {
		return sname;
	}
	public void setSname(String sname) {
		this.sname = sname;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public Date getBirthday() {
		return birthday;
	}
	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}
	public String getPic() {
		return pic;
	}
	public void setPic(String pic) {
		this.pic = pic;
	}
	public String getCardId() {
		return cardId;
	}
	public void setCardId(String cardId) {
		this.cardId = cardId;
	}

	@Override
	public String toString() {
		return "Student{" +
				"sid=" + sid +
				", sname='" + sname + '\'' +
				", address='" + address + '\'' +
				", birthday=" + birthday +
				", pic='" + pic + '\'' +
				", cardId='" + cardId + '\'' +
				", gender='" + gender + '\'' +
				", clazz=" + clazz +
				'}';
	}
}
